package com.bestillet.defaultmultishop;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

public class DeselectDialog extends Dialog {
	private MixActivity context;
	private ListView list;
	private Button add;
	
	private Mix mix;
	
	private OnItemClickListener listener = new OnItemClickListener() {
		@Override
		public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
			TextView t = (TextView) view.findViewById(R.id.lblOptionName);
			if (!mix.getChoices().contains(mix.getOptions().get(position))) {
				mix.getChoices().add(mix.getOptions().get(position));
				t.setTextColor(Color.RED);
				t.setPaintFlags(Paint.STRIKE_THRU_TEXT_FLAG);
			} else {
				mix.getChoices().remove(mix.getOptions().get(position));
				t.setTextColor(Color.BLACK);
				t.setPaintFlags(t.getPaintFlags() & (~ Paint.STRIKE_THRU_TEXT_FLAG));
			}
		}
	};
	
	private View.OnClickListener click = new View.OnClickListener() {
		@Override
		public void onClick(View v) {
			context.updateChoices();
			dismiss();
		}
	};

	public DeselectDialog(Context context, Mix mix) {
		super(context);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.dialog_check);
		
		this.context = (MixActivity) context;
		this.mix = mix;
		
		DeselectArrayAdapter adapter = new DeselectArrayAdapter(context, mix.getOptions(), mix.getChoices());
		list = (ListView) findViewById(android.R.id.list);
		list.setAdapter(adapter);
		list.setOnItemClickListener(listener);
		
		add = (Button) findViewById(R.id.btnDone);
		add.setOnClickListener(click);
	}
}